<template>
  <div class="app-container">
    <!-- 高级查询 -->
    <el-form v-show="searchVisible" ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item label="消息接收方名称:">
        <el-input v-model="queryParams.toName" size="small" placeholder="请输入消息接收方名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="接收公司标识:">
        <el-input v-model="queryParams.toCompanyId" size="small" placeholder="请输入接收公司标识" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="消息接收方:">
        <el-input v-model="queryParams.toId" size="small" placeholder="请输入消息接收方" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="是否已读:">
        <el-input v-model="queryParams.readYn" size="small" placeholder="请输入是否已读" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="相关消息ID:">
        <el-input v-model="queryParams.relatedMesgId" size="small" placeholder="请输入相关消息ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="广播群发还是私聊:">
        <el-input v-model="queryParams.publicOrPrivate" size="small" placeholder="请输入广播群发还是私聊" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button v-hasPermission="['basic:baoliMesg:insert']" type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['basic:baoliMesg:update']" type="success" icon="el-icon-edit" size="mini" :disabled="isSingle" @click="handleEdit">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['basic:baoliMesg:delete']" type="danger" icon="el-icon-delete" size="mini" :disabled="isMultiple" @click="handleRemove">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['basic:baoliMesg:export']" type="warning" icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :show-search.sync="searchVisible" @queryTable="handleQuery" />
    </el-row>

    <!-- 数据列表 -->
    <el-table v-loading="loading" :data="page.records" highlight-current-row @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<el-table-column label="序号" type="index" align="center"/>
      <el-table-column label="消息接收方名称" align="center" prop="toName" />

      <el-table-column label="接收公司标识" align="center" prop="toCompanyId" />

      <el-table-column label="消息接收方" align="center" prop="toId" />
      <el-table-column label="是否已读" align="center" prop="readYn" />
      <el-table-column label="消息内容" align="center" prop="mesgBody" />
      <el-table-column label="消息类型" align="center" prop="mesgType" />
      <el-table-column label="相关消息ID" align="center" prop="relatedMesgId" />
      <el-table-column label="广播群发还是私聊" align="center" prop="publicOrPrivate" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="" align="center" prop="uploadPicOneName" />
      <el-table-column label="" align="center" prop="uploadPicTwoName" />
      <el-table-column label="" align="center" prop="uploadPicCt" />
      <el-table-column label="" align="center" prop="uploadPicThreeName" />
      <el-table-column label="" align="center" prop="uploadPicFourName" />
      <el-table-column label="" align="center" prop="uploadPicFiveName" />
      <el-table-column label="" align="center" prop="uploadPicSixName" />
      <el-table-column label="" align="center" prop="uploadPicSevenName" />
      <el-table-column label="" align="center" prop="uploadPicEightName" />
      <el-table-column label="" align="center" prop="uploadPicNineName" />
      <el-table-column label="" align="center" prop="uploadPicTenName" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-hasPermission="['basic:baoliMesg:update']" size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)">修改</el-button>
          <el-button v-hasPermission="['basic:baoliMesg:delete']" size="mini" type="text" icon="el-icon-delete" @click="handleRemove(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <pagination v-show="page.total>0" :total="page.total" :page.sync="page.current" :limit.sync="page.pageSize" @pagination="handleQuery" />

    <!-- 添加/修改对话框 -->
    <el-dialog :title="baoliMesgFormDialog.title" :visible.sync="baoliMesgFormDialog.visible" :close-on-click-modal="false" :before-close="resetBaoliMesgFormDialog" width="500px" append-to-body>
      <el-form ref="baoliMesgForm" :model="baoliMesgFormData" :rules="baoliMesgFormRules" label-width="80px">
        <el-form-item label="消息接收方名称" prop="toName">
          <el-input v-model="baoliMesgFormData.toName" placeholder="请输入消息接收方名称" />
        </el-form-item>
        <el-form-item label="消息发送方名称" prop="fromName">
          <el-input v-model="baoliMesgFormData.fromName" placeholder="请输入消息发送方名称" />
        </el-form-item>
        <el-form-item label="接收公司标识" prop="toCompanyId">
          <el-input v-model="baoliMesgFormData.toCompanyId" placeholder="请输入接收公司标识" />
        </el-form-item>
        <el-form-item label="消息发送方" prop="fromId">
          <el-input v-model="baoliMesgFormData.fromId" placeholder="请输入消息发送方" />
        </el-form-item>
        <el-form-item label="消息接收方" prop="toId">
          <el-input v-model="baoliMesgFormData.toId" placeholder="请输入消息接收方" />
        </el-form-item>
        <el-form-item label="是否已读" prop="readYn">
          <el-input v-model="baoliMesgFormData.readYn" placeholder="请输入是否已读" />
        </el-form-item>
        <el-form-item label="消息内容" prop="mesgBody">
          <el-input v-model="baoliMesgFormData.mesgBody" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="相关消息ID" prop="relatedMesgId">
          <el-input v-model="baoliMesgFormData.relatedMesgId" placeholder="请输入相关消息ID" />
        </el-form-item>
        <el-form-item label="广播群发还是私聊" prop="publicOrPrivate">
          <el-input v-model="baoliMesgFormData.publicOrPrivate" placeholder="请输入广播群发还是私聊" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="baoliMesgFormData.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="" prop="uploadPicOneName">
          <el-input v-model="baoliMesgFormData.uploadPicOneName" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="uploadPicTwoName">
          <el-input v-model="baoliMesgFormData.uploadPicTwoName" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="uploadPicCt">
          <el-input v-model="baoliMesgFormData.uploadPicCt" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="uploadPicThreeName">
          <el-input v-model="baoliMesgFormData.uploadPicThreeName" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="uploadPicFourName">
          <el-input v-model="baoliMesgFormData.uploadPicFourName" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="uploadPicFiveName">
          <el-input v-model="baoliMesgFormData.uploadPicFiveName" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="uploadPicSixName">
          <el-input v-model="baoliMesgFormData.uploadPicSixName" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="uploadPicSevenName">
          <el-input v-model="baoliMesgFormData.uploadPicSevenName" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="uploadPicEightName">
          <el-input v-model="baoliMesgFormData.uploadPicEightName" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="uploadPicNineName">
          <el-input v-model="baoliMesgFormData.uploadPicNineName" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="uploadPicTenName">
          <el-input v-model="baoliMesgFormData.uploadPicTenName" placeholder="请输入" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmBaoliMesgFormDialog">确 定</el-button>
        <el-button @click="resetBaoliMesgFormDialog">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import BaoliMesgApi from '@/api/basic/BaoliMesgApi'

const defaultBaoliMesgFormData = {
  toName: null,

  fromName: null,

  toCompanyId: null,

  fromId: null,

  toId: null,

  readYn: null,

  mesgBody: null,

  mesgType: null,

  relatedMesgId: null,

  publicOrPrivate: null,

  uploadPicOneName: null,

  uploadPicTwoName: null,

  uploadPicCt: null,

  uploadPicThreeName: null,

  uploadPicFourName: null,

  uploadPicFiveName: null,

  uploadPicSixName: null,

  uploadPicSevenName: null,

  uploadPicEightName: null,

  uploadPicNineName: null,

  uploadPicTenName: null,

}
export default {
  name: 'BaoliMesgList',
  data() {
    return {
      options: {
        sysYnTypeOptions: this.$constant.sysYnTypeOptions
      },
      queryParams: {
        toName: null,
        fromName: null,
        toCompanyId: null,
        fromId: null,
        toId: null,
        readYn: null,
        mesgBody: null,
        mesgType: null,
        relatedMesgId: null,
        publicOrPrivate: null,
        uploadPicOneName: null,
        uploadPicTwoName: null,
        uploadPicCt: null,
        uploadPicThreeName: null,
        uploadPicFourName: null,
        uploadPicFiveName: null,
        uploadPicSixName: null,
        uploadPicSevenName: null,
        uploadPicEightName: null,
        uploadPicNineName: null,
        uploadPicTenName: null,
        isValid: this.$constant.Y
      },
      page: {
        current: 1,
        pageSize: 10,
        total: 0,
        records: []
      },
      baoliMesgFormDialog: {
        title: '',
        visible: false
      },
      baoliMesgFormData: Object.assign({}, defaultBaoliMesgFormData),
      baoliMesgFormRules: {
      },
      loading: true,
      searchVisible: true,
      multipleSelection: [],
      isSingle: true,
      isMultiple: true
    }
  },
  created() {
    this.handleQuery()
    this.loadOptions()
  },
  methods: {
    loadOptions() {
    },
    handleAdd() {
      this.openBaoliMesgFormDialog()
    },
    handleRemove(row) {
      const ids = row.id || this.multipleSelection.map(item => item.id)
      this.$confirm('是否确认删除数据?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return BaoliMesgApi.remove(ids)
      }).then(() => {
        this.handleQuery()
        this.$message.success('删除成功')
      })
    },
    handleEdit(row) {
      const id = row.id || this.multipleSelection.map(item => item.id)[0]
      this.openBaoliMesgFormDialog(id)
    },
    handleQuery() {
      this.loading = true
      BaoliMesgApi.page(this.queryParams, this.page).then(response => {
        this.page.records = response.data.records
        this.page.total = response.data.total
        this.loading = false
      }, () => {
        this.loading = false
      })
    },
    handleExport() {
      this.$confirm('是否确认导出数据?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return BaoliMesgApi.exportData(this.queryParams)
      }).then(response => {
        this.$common.download(response.msg)
      })
    },
    openBaoliMesgFormDialog(id) {
      this.baoliMesgFormDialog.visible = true
      if (id) {
        this.baoliMesgFormDialog.title = '消息-修改'
        BaoliMesgApi.get(id).then(response => {
          this.baoliMesgFormData = {
            ...this.baoliMesgFormData,
            ...response.data
          }
        })
      } else {
        this.baoliMesgFormDialog.title = '消息-添加'
      }
    },
    confirmBaoliMesgFormDialog() {
      this.$refs['baoliMesgForm'].validate(valid => {
        if (valid) {
          if (this.baoliMesgFormData.id) {
            BaoliMesgApi.edit(this.baoliMesgFormData).then(response => {
              this.$message.success('修改成功')
              this.resetBaoliMesgFormDialog()
              this.handleQuery()
            })
          } else {
            BaoliMesgApi.add(this.baoliMesgFormData).then(response => {
              this.$message.success('添加成功')
              this.resetBaoliMesgFormDialog()
              this.handleQuery()
            })
          }
        }
      })
    },
    resetBaoliMesgFormDialog() {
      this.baoliMesgFormDialog = {
        title: '',
        visible: false
      }
      this.baoliMesgFormData = Object.assign({}, defaultBaoliMesgFormData)
      this.resetForm('baoliMesgForm')
    },
    handleSelectionChange(selection) {
      this.multipleSelection = selection
      this.isSingle = selection.length !== 1
      this.isMultiple = !selection.length
    },
    resetQuery() {
      this.page.current = 1
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>
